//
//  CGFloat+Ex.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/23.
//

public extension CGFloat {
    
    static var max: CGFloat {
        CGFloat(MAXFLOAT)
    }
    
    var compressionQuality: CGFloat {
        if self > 30000000 {
            return 30000000 / self
        }else if self > 15000000 {
            return 10000000 / self
        }else if self > 10000000 {
            return 6000000 / self
        }else {
            return 3000000 / self
        }
    }
    
    var transitionCompressionQuality: CGFloat {
        if self > 6000000 {
            return 3000000 / self
        }else if self > 3000000 {
            return 1000000 / self
        }else if self > 1000000 {
            return 600000 / self
        }else {
            return 1000000 / self
        }
    }
}

public extension Float {
    //float 转 分秒
    func floatToMinuteSecond() -> String {
        // 将 Float 类型的时间转换为整数秒
        let totalSeconds = Int(self)
        // 计算分钟数
        let minutes = totalSeconds / 60
        // 计算剩余的秒数
        let seconds = totalSeconds % 60
        // 将分钟数和秒数格式化为两位数的字符串
        let minuteString = String(format: "%02d", minutes)
        let secondString = String(format: "%02d", seconds)
        // 拼接成分秒格式的字符串
        return "\(minuteString):\(secondString)"
    }
}

public extension Float {
    /// 四舍五入到指定小数位
    func roundedPlaces(_ places: Int = 2) -> Float {
        let divisor = pow(10.0, Float(places))
        return (self * divisor).rounded() / divisor
    }
}

public extension Double {
    /// 四舍五入到指定小数位
    func roundedPlaces(_ places: Int = 2) -> Double {
        let divisor = pow(10.0, Double(places))
        return (self * divisor).rounded() / divisor
    }
}
